/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Damier.java
 *
 * Created on 7 sept. 2011, 20:17:23
 */
package vue;

import java.util.Observable;
import java.util.Observer;
import model.jeu_de_dame.Case;
import model.jeu_de_dame.Damier;

/**
 *
 * @author nabil
 */
public class DamierVue extends javax.swing.JPanel implements Observer{
     private static  final int taille = 400;
    /** Creates new form Damier */
    CaseVue [][] mesCases;
    
    public DamierVue(Damier d) {
        
        initComponents();
        this.setContenu(d.getMesCases());
        
    }
    
    public void setContenu(Case[][] lesCases)
    {
        mesCases = new CaseVue[lesCases.length][lesCases.length];
        setLayout(new java.awt.GridLayout(lesCases.length, lesCases.length));
        int size  = this.getWidth()/lesCases.length;
        for(int i = 0; i < lesCases.length;i++)
        {
            for(int j = 0; j< lesCases[i].length; j++)
            {   
                mesCases[i][j] = new CaseVue(lesCases[i][j],j,i,size);
                this.add(mesCases[i][j]);
                
            }
        }
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        setBorder(javax.swing.BorderFactory.createEtchedBorder());
        setAlignmentX(0.0F);
        setAlignmentY(0.0F);
        setMinimumSize(new java.awt.Dimension(200, 200));
        setName("Form"); // NOI18N
        addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                formMouseClicked(evt);
            }
        });
        addComponentListener(new java.awt.event.ComponentAdapter() {
            public void componentResized(java.awt.event.ComponentEvent evt) {
                formComponentResized(evt);
            }
        });
        addContainerListener(new java.awt.event.ContainerAdapter() {
            public void componentAdded(java.awt.event.ContainerEvent evt) {
                formComponentAdded(evt);
            }
        });
        addHierarchyBoundsListener(new java.awt.event.HierarchyBoundsListener() {
            public void ancestorMoved(java.awt.event.HierarchyEvent evt) {
            }
            public void ancestorResized(java.awt.event.HierarchyEvent evt) {
                formAncestorResized(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 340, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 311, Short.MAX_VALUE)
        );
    }// </editor-fold>//GEN-END:initComponents

    private void formMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_formMouseClicked

    }//GEN-LAST:event_formMouseClicked

private void formComponentAdded(java.awt.event.ContainerEvent evt) {//GEN-FIRST:event_formComponentAdded

}//GEN-LAST:event_formComponentAdded

private void formComponentResized(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_formComponentResized
// TODO add your handling code here:
}//GEN-LAST:event_formComponentResized

private void formAncestorResized(java.awt.event.HierarchyEvent evt) {//GEN-FIRST:event_formAncestorResized
// TODO add your handling code here:
}//GEN-LAST:event_formAncestorResized

    // Variables declaration - do not modify//GEN-BEGIN:variables
    // End of variables declaration//GEN-END:variables

    public void update(Observable o, Object arg) {
       try
       {
          
       }catch(Exception e)
       {
           
       }
    }
}
